<template>
  <el-dialog title="编辑评分信息" :visible.sync="dialogVisible" :close-on-click-modal="false"
             :close-on-press-escape="false" :before-close="handleClose" @close="$emit('update:visible',false)"
             top="100px">
    <el-form :model="editForm" label-width="160px" :rules="editFormRules" ref="editForm">
      <el-form-item label="名称：" prop="name">
        <el-input v-model="editForm.name" auto-complete="off" placeholder="填写名称"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click.native="resetForm" size="small">取消</el-button>
      <el-button type="primary" @click.native="editSubmit" size="small">提交</el-button>
    </div>
  </el-dialog>
</template>
<script>
  export default {
    name: 'Dialog',
    props: ['visible', 'editId'],
    watch: {
      visible () {
        this.dialogVisible = this.visible
      }
    },

    data () {
      return {
        dialogVisible: false,
        editForm: {
          name: ''
        }, // 编辑界面数据
        editFormRules: {
          name: [
            {required: true, message: '请填写评分名称', trigger: 'blur'}
          ]
        }
      }
    },
    created () {

    },
    methods: {
      handleClose () {
        this.dialogVisible = false
      },
      resetForm () {
        this.dialogVisible = false
      },
      editSubmit () {
        let url_ = this.api.setting.cornerAdd
        if (this.editId) {
          url_ = this.api.admin_section_edit
          this.editForm.id = this.editId.id
        }
        this.$post(url_, this.editForm).then((response) => {
          if (response.code === 0) {
            this.$emit('refreshFn')
            this.$message({
              message: '编辑成功',
              type: 'success'
            })
            this.dialogVisible = false
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      }
    }
  }
</script>
